package com.orilife.adapter;

import java.util.List;

import com.example.orllife.R;
import com.orilife.bean.Address;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class AddressAdapter extends BaseAdapter {
	List<Address>  addressList;
	Context context;

	public AddressAdapter(Context context) {
		super();
	
		this.context = context;
	}
	public void setData(List<Address>  addressList){
		this.addressList = addressList;
		this.notifyDataSetChanged();
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return addressList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
	class ViewHolder{
		TextView nameTv,phoneTv,addressTv;
		
		
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		final ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(
					R.layout.myaddressitemlayout, null);

			holder.nameTv = (TextView) convertView
					.findViewById(R.id.addressownertv);
			

			holder.phoneTv = (TextView) convertView
					.findViewById(R.id.addressownerphonetv);

			holder.addressTv = (TextView) convertView
					.findViewById(R.id.owneraddresstv);
			convertView.setTag(holder);
		}else{
			holder = (ViewHolder) convertView.getTag();
		}
		
		holder.nameTv.setText(addressList.get(position).getName());
		holder.phoneTv.setText(addressList.get(position).getPhone());
		holder.addressTv.setText(addressList.get(position).getRegion()+addressList.get(position).getRegionDetails());
		return convertView;
	}

}
